package com.heima.user.controller.v1;

import com.heima.api.user.ApUserRealnameControllerApi;
import com.heima.common.constants.admin.AdminConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.user.dtos.AuthDto;
import com.heima.user.service.ApUserRealnameService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @ClassName ApUserRealnameController
 * @Description TODO
 * @Author AWei
 * @DATE 2021/4/12 17:48
 * @Version 1.0
 */
@RestController
@RequestMapping("api/v1/auth")
public class ApUserRealnameController implements ApUserRealnameControllerApi {

    @Resource
    private ApUserRealnameService apUserRealnameService;

    /**
     * @param dto 用户审核类对象
     * @return 用户认证表查询结果对象
     * @Description 按照状态查询用户认证列表
     */
    @Override
    @PostMapping("list")
    public ResponseResult loadListByStatus(@RequestBody AuthDto dto) {
        return apUserRealnameService.loadListByStatus(dto);
    }

    /**
     * @Description 审核通过
     * @param dto 审核用户对象
     * @return 审核结果
     */
    @PostMapping("authPass")
    @Override
    public ResponseResult authPass(@RequestBody AuthDto dto) {
        return apUserRealnameService.updateStatusById(dto, AdminConstants.PASS_AUTH);
    }

    /**
     * @Description 审核失败
     * @param dto 审核用户对象
     * @return 审核结果
     */
    @PostMapping("authFail")
    @Override
    public ResponseResult authFail(@RequestBody AuthDto dto) {
        return apUserRealnameService.updateStatusById(dto, AdminConstants.FAIL_AUTH);
    }
}
